<?php

class AnswerPeer extends BaseAnswerPeer
{
      public static function doSelectForTeacher(Criteria $criteria, PropelPDO $con = null)
    {
        if ($con === null)
        {
            $con = Propel::getConnection(AnswerPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        if (!$criteria->hasSelectClause())
        {
            $criteria = clone $criteria;
            AnswerPeer::addSelectColumns($criteria);
        }
        if(!sfContext::getInstance()->getUser()->getGuardUser()->getIsSuperAdmin())
        {
            $criteria->addJoin(AnswerPeer::QUESTION_ID, QuestionPeer::ID);
            $criteria->addJoin(QuestionPeer::TEST_ID, TestPeer::ID);
            $criteria->addJoin(TestPeer::TEST_BLOCK_ID, TestBlockPeer::ID);
            $criteria->addJoin(TestBlockPeer::SUBJECT_ID, UserSubjectPeer::SUBJECT_ID);
            $criteria->addJoin(UserSubjectPeer::USER_ID, sfContext::getInstance()->getUser()->getGuardUser()->getId());
        }
        return AnswerPeer::doSelect($criteria);
    }

    public static function doCountForTeacher(Criteria $criteria, PropelPDO $con = null)
    {
        if ($con === null)
        {
            $con = Propel::getConnection(AnswerPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        if (!$criteria->hasSelectClause())
        {
            $criteria = clone $criteria;
            AnswerPeer::addSelectColumns($criteria);
        }
        if(!sfContext::getInstance()->getUser()->getGuardUser()->getIsSuperAdmin())
        {
            $criteria->addJoin(AnswerPeer::QUESTION_ID, QuestionPeer::ID);
            $criteria->addJoin(QuestionPeer::TEST_ID, TestPeer::ID);
            $criteria->addJoin(TestPeer::TEST_BLOCK_ID, TestBlockPeer::ID);
            $criteria->addJoin(TestBlockPeer::SUBJECT_ID, UserSubjectPeer::SUBJECT_ID);
            $criteria->addJoin(UserSubjectPeer::USER_ID, sfContext::getInstance()->getUser()->getGuardUser()->getId());
        }
        return AnswerPeer::doCount($criteria);
    }
}
